from typing import List

from server.framework.utils.kubernetes.kubernetes_client import KubernetesClient
from server.framework.utils.kubernetes.schemas.node_info import NodeInfo
from server.framework.utils.prometheus_manager import PrometheusManager


class SystemInfoService:
    def get_all_nodes(self) -> List[NodeInfo]:
        kubernetes_manager = KubernetesClient()
        node_info = kubernetes_manager.list_node_info()
        return node_info

    def load_node_metric(self, node_lists: list, metrics: list, start: str, end: str, step: str) -> dict:
        prometheus_manager = PrometheusManager()
        monitor_value = {}
        for metric_name in metrics:
            if metric_name in prometheus_manager.node_query:
                results = prometheus_manager.query_metrics(instances=node_lists,
                                                           query=prometheus_manager.node_query[metric_name],
                                                           start=start,
                                                           end=end,
                                                           step=step)
                monitor_value[metric_name] = prometheus_manager.get_value(results)
        return monitor_value
